from django.shortcuts import render, redirect
from django.http import HttpResponse, JsonResponse
from ..models import Department, UserInfo, PrettyNum, Task, Order
from django import forms
from django.forms import Form, ModelForm
from django.utils.safestring import mark_safe
from ..utils.pagination import Pagination
from ..utils.bootstrap import BootStrapModelForm
from ..utils.form import UserModelForm, PrettynumModelForm, PrettynumEditModelForm
from django.core.validators import RegexValidator
from django.core.exceptions import ValidationError
from django.views.decorators.csrf import csrf_exempt
import json
from datetime import datetime
from django.views.decorators.csrf import csrf_exempt
import random

def chart_list(request):
    return render(request, 'chart_list.html')

def chart_bar(request):
    legend = ['丁佑强', '林伟']
    series_list = [
        {
            'name': '丁佑强',
            'type': 'bar',
            'data': [5, 20, 36, 10, 10, 20]
        },
        {
            'name': '林伟',
            'type': 'bar',
            'data': [15, 22, 136, 40, 13, 50]
        }
    ]
    x_axis = ['1月','2月','3月','4月','5月','6月','7月']
    result = {
        'status': True,
        'data': {
            'legend':legend,
            'series_list': series_list,
            'x_axis': x_axis,
        }
    }
    return JsonResponse(result)

def chart_pie(request):
    result = {
        'status': True,
        'data': [
            {'value': 335, 'name': 'IT'},
            {'value': 310, 'name': '运营'},
            {'value': 234, 'name': '新媒体'},
        ]
    }
    return JsonResponse(result)

def chart_line(request):
    legend = ['邮件营销', '联盟广告', '视频广告', '直接访问', '搜索引擎']
    series_list = [
        {
            'name': '邮件营销',
            'type': 'line',
            'stack': '总量',
            'data': [120, 132, 101, 134, 90, 230, 210]
        },
        {
            'name': '联盟广告',
            'type': 'line',
            'stack': '总量',
            'data': [220, 182, 191, 234, 290, 330, 310]
        },
        {
            'name': '视频广告',
            'type': 'line',
            'stack': '总量',
            'data': [150, 232, 201, 154, 190, 330, 410]
        },
        {
            'name': '直接访问',
            'type': 'line',
            'stack': '总量',
            'data': [320, 332, 301, 334, 390, 330, 320]
        },
        {
            'name': '搜索引擎',
            'type': 'line',
            'stack': '总量',
            'data': [820, 932, 901, 934, 1290, 1330, 1320]
        }
    ]
    x_axis = ['周一', '周二', '周三', '周四', '周五', '周六', '周日']
    result = {
        'status': True,
        'data': {
            'legend':legend,
            'series_list': series_list,
            'x_axis': x_axis,
        }
    }
    return JsonResponse(result)